1 //+------------------------------------------------------------------+
\r
2 //| Keltner Channels.mq4 |
\r
3 //| Coded by Gilani |
\r
4 //| Copyright © 2005, MetaQuotes Software Corp. |
\r
5 //| http://www.metaquotes.net |
\r
6 //+------------------------------------------------------------------+
\r
7 #property copyright "Copyright © 2005, MetaQuotes Software Corp."
\r
8 #property link "http://www.metaquotes.net"
\r
9 //+------------------------------------------------------------------+
\r
10 //| Custom indicator initialization function |
\r
11 //+------------------------------------------------------------------+
\r
12 #property indicator_chart_window
\r
13 #property indicator_buffers 3
\r
14 #property indicator_color1 Red
\r
15 #property indicator_color2 Green
\r
16 #property indicator_color3 Black
\r
18 double upper[], middle[], lower[];
\r
19 extern int period=10;
\r
21 //+------------------------------------------------------------------+
\r
23 //+------------------------------------------------------------------+
\r
26 SetIndexStyle(0,DRAW_LINE);
\r
28 SetIndexDrawBegin(0,0);
\r
29 SetIndexBuffer(0,upper);
\r
30 SetIndexStyle(1,DRAW_LINE);
\r
32 SetIndexDrawBegin(1,0);
\r
33 SetIndexBuffer(1,middle);
\r
34 SetIndexStyle(2,DRAW_LINE);
\r
36 SetIndexDrawBegin(2,0);
\r
37 SetIndexBuffer(2,lower);
\r
42 //+------------------------------------------------------------------+
\r
43 //| Custor indicator deinitialization function |
\r
44 //+------------------------------------------------------------------+
\r
47 //---- TODO: add your code here
\r
51 //+------------------------------------------------------------------+
\r
52 //| Custom indicator iteration function |
\r
53 //+------------------------------------------------------------------+
\r
57 int counted_bars=IndicatorCounted();
\r
58 if(counted_bars<0) return(-1);
\r
59 if(counted_bars>0) counted_bars--;
\r
60 limit=Bars-counted_bars;
\r
63 for(int x=0; x<limit; x++)
\r
65 middle[x]=iMA(NULL, 0, period, 0, MODE_SMA, PRICE_TYPICAL, x);
\r
66 avg =findAvg(period, x);
\r
67 upper[x]=middle[x] + avg;
\r
68 lower[x]=middle[x] - avg;
\r
72 //+------------------------------------------------------------------+
\r
73 double findAvg(int period, int shift)
\r
76 for(int x=shift;x<(shift+period);x++)
\r
78 sum+=High[x]-Low[x];
\r
83 //+------------------------------------------------------------------+